/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/11/28
*/
#ifndef __EDUI_LUAHELPER_H__
#define __EDUI_LUAHELPER_H__

#include "base/LuaBase.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

class LuaClassBase
{
public:
    virtual void Release() = 0;
    virtual void* GetCObj() = 0;
};

#define LuaHelperNS EDUI_NAMESPACE::LuaHelper
namespace LuaHelper{

//register all lua
void RegisterLuaAll(LuaState *L);

//get the table where saved Luaclass metatables
LuaObject GetTableOfMetas(LuaState *L);
//create a table to saved Luaclass metatables.return the table.
LuaObject AddToMetas(LuaState *L, const char* key, const char* parent = 0);
//get the table from saved Luaclass metatables
LuaObject GetFromMetas(LuaState *L, const char* key);
//remove the table from saved Luaclass metatables
void RemoveFromMetas(LuaState *L, const char* key);

//get the table where saved Luaclass objects
LuaObject GetTableOfObjs(LuaState *L);
//create a table to saved Luaclass objects.return the table.
LuaObject AddToObjs(LuaState *L, void* key);
//get the table from saved Luaclass objects
LuaObject GetFromObjs(LuaState *L, void* key);
//remove the table from saved Luaclass objects
void RemoveFromObjs(LuaState *L, void* key);

//add a event to Objs
bool SetEventToObjs(LuaState *L, void* key, const char* evtname, LuaObject event);
//get a event from Objs
LuaObject GetEventFromObjs(LuaState *L, void* key, const char* eventname);
//remove the event from Objs
void RemoveEventFromObjs(LuaState *L, void* key, const char* eventname);

//add a timer to Objs
bool SetTimerToObjs(LuaState *L, void* key, TimerID id, LuaObject callback);
//get a timer from Objs
LuaObject GetTimerFromObjs(LuaState *L, void* key, TimerID id);
//remove the timer from Objs
void RemoveTimerFromObjs(LuaState *L, void* key, TimerID id);


//set a c++ pointer to table.
void SetCObject(LuaObject obj, LuaClassBase* cobj);
//get the c++ pointer if had.
LuaClassBase* GetCObject(LuaObject obj);
//get the c++ pointer's data
void* GetCObjectData(LuaObject obj);

}
EDUI_NAMESPACE_END

#endif
#endif